package ty.tryagainforever1129.pikachumemory;
import ty.tryagainforever1129.pikachumemory.adaper.LeaderBoardAdapter;
import ty.tryagainforever1129.pikachumemory.common.Constant;
import ty.tryagainforever1129.pikachumemory.common.Util;
import ty.tryagainforever1129.pikachumemory.model.UserModel;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;

public class LeaderBoardActivity extends Activity {
    private TextView content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.leader_boards_layout);
        content = (TextView) findViewById(R.id.content);
        content.setText("content");
        // if has data.
        Intent intent = getIntent();
        // get user information for intent.
        UserModel newUser = new UserModel();
        newUser.setUserName(intent.getStringExtra(Constant.INTENT_LEADER_BOARDS_USER_NAME));
        newUser.setScrore(intent.getIntExtra(Constant.INTENT_LEADER_BOARDS_SCORE, Constant.COMMON_0));
        if(newUser.getUserName() != null && newUser.getScrore() > Util.getMinScore(LeaderBoardActivity.this)) {
            // add new user to database.
            Util.addUserModelList(LeaderBoardActivity.this, newUser);
        }
        // display user list to UI.
        ((ListView) findViewById(R.id.list)).setAdapter(new LeaderBoardAdapter(this, Util.getUserModelList(this)));
    }
}
